package gui.gui2d.lan;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;


public class OurTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	
	public OurTableModel() {
		servers= new ArrayList<IpNameServer>();
	}
	
	
	String[] columnNames = {"Indirizzo ip" , "Nick"};
	ArrayList<IpNameServer> servers ;


	



	public void addValue(String ip ,String nome){
		if(!servers.contains(new IpNameServer(ip,nome))){
			servers.add(new IpNameServer(ip,nome));
		}
	}
	
	public void removeValue(String ip){
		if(servers.contains(new IpNameServer(ip, null))){
			servers.remove(new IpNameServer(ip, null));
		}
	}


	@Override
	public boolean isCellEditable(int row, int column) {
		//all cells false
		return false;
	}


	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return columnNames.length;
	}


	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
	
		return servers.size(); 
	}


	@Override
	public Object getValueAt(int arg0, int arg1) {
		if(arg1==0){
			return servers.get(arg0).ip;
		}else{
			return servers.get(arg0).nome;

		}
	}


	@Override
	public String getColumnName(int column) {
		// TODO Auto-generated method stub
		return columnNames[column];
	}




}